<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>个人中心</title>
    <link rel="stylesheet" href="../css/page-health-orderNotice.css"/>
    <link rel="stylesheet" href="../css/gr-personal-center.css"/>
    <script src="../plugins/jquery/dist/jquery.min.js"></script>
    <script src="../plugins/healthmobile.js"></script>
    <script src="../plugins/vue/vue.js"></script>
    <script src="../plugins/vue/axios-0.18.0.js"></script>
    <link rel="stylesheet" href="../plugins/element-ui/lib/theme-chalk/index.css"/>
    <script src="../plugins/element-ui/lib/index.js"></script>

    <style>

        .order-btn {
            width: 100%;
            font-size: 18px;
            color: #fff;
            border-radius: 10px;
            padding: 3.6% 0;
            border: none;
            background-image: linear-gradient(90deg, #26acff, #0088dc);
        }

        .gr-hr-style-1 {
            border: none;
            border-top: 20px solid #E8E8E8;
        }

        .gr-hr-style-2 {
            border: none;
            border-top: 2px solid #F3F2F7;
        }

    </style>

</head>
<body>

<div id="app" class="app">
    <!-- 页面头部 -->
    <div class="top-header">
        <span class="f-left"><i class="icon-back" onclick="history.go(-1)"></i></span>
        <span class="center">传智健康</span>
        <span class="f-right">
            <el-row class="block-col-2">
                <el-dropdown trigger="click">
                    <span class="el-dropdown-link">
                        <i class="el-icon-more"></i>
                    </span>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item icon="el-icon-s-home">
                            <el-button type="text"
                                       @click="toIndex()">首&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;页</el-button>
                        </el-dropdown-item>
                        <el-dropdown-item icon="el-icon-film">
                            <el-button type="text" @click="toHistoryRecord()">历史预约</el-button>
                        </el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </el-row>
        </span>
    </div>
    <!-- 页面内容 -->
    <div class="contentBox">
        <div class="notice-article">
            <div class="info-title">
                <span class="gr-name">账号资料</span>
            </div>
            <hr class="gr-hr-style-1"/>

            <div style="width: 100%; ">
                <div style="width: 80%;margin: auto">
                    <el-form :label-position="labelPosition" ref="personalData" :model="personalData" label-width="20%">

                        <el-form-item label="用户名">
                            <el-input v-model="personalData.name" placeholder="未设置"></el-input>
                        </el-form-item>
                        <hr class="gr-hr-style-2"/>

                        <el-form-item label="性别">
                            <el-radio-group v-model="personalData.sex">
                                <el-radio label="1" value="1">男</el-radio>
                                <el-radio label="2" value="2">女</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <hr class="gr-hr-style-2"/>

                        <el-form-item label="手机号">
                            <el-input v-model="personalData.phoneNumber" placeholder="未设置" disabled></el-input>
                        </el-form-item>
                        <hr class="gr-hr-style-2"/>

                        <el-form-item label="身份证号码">
                            <el-input id="gr-idCard" v-model="personalData.idCard"></el-input>
                        </el-form-item>
                        <hr class="gr-hr-style-2"/>

                        <el-form-item label="生日">
                            <el-date-picker type="date" placeholder="未设置" v-model="personalData.birthday"
                                            style="width: 100%;" disabled></el-date-picker>
                        </el-form-item>
                        <hr class="gr-hr-style-2"/>

                        <el-form-item label="邮箱">
                            <el-input v-model="personalData.email" placeholder="未设置"></el-input>
                        </el-form-item>
                        <hr class="gr-hr-style-2"/>

                        <el-form-item label="注册日期">
                            <el-date-picker type="date" placeholder="未设置" v-model="personalData.regTime" disabled
                                            style="width: 100%;"></el-date-picker>
                        </el-form-item>


                    </el-form>

                    <div class="box-button">
                        <button @click="changePersonalCenter()" type="button" class="btn order-btn">提交修改</button>
                    </div>

                </div>
            </div>

        </div>
    </div>
</div>

</body>

<script>
    var vue = new Vue({
        el: '#app',
        data: {

            labelPosition: 'left',
            isChangeIdCard:true,
            personalData: {}

        },

        methods: {

            getMyCookie(key) {
                var val = "";
                // 对cookie操作
                var cookies = document.cookie;
                cookies = cookies.replace(/\s/, "");
                var cookie_array = cookies.split(";");
                for (i = 0; i < cookie_array.length; i++) {
                    // yh_mch=lilei
                    var cookie = cookie_array[i];
                    var array = cookie.split("=");
                    if (array[0] == key) {
                        val = array[1];
                    }
                }
                return val;
            },

            toIndex() {
                window.location.href = "index.html";
            },

            toHistoryRecord() {
                window.location.href = "historyRecord.html";
            },

            findInfo() {

                let telephone = this.getMyCookie("telephone");

                axios.get("/personalCenter/getPersonData.do?telephone=" + telephone).then((resp) => {
                    if (resp.data.flag) {
                        this.personalData = resp.data.data;
                        idCard = this.personalData.idCard;
                        if (idCard != null && idCard.length > 0) {
                            this.isChangeIdCard = false;
                            $("#gr-idCard").attr("disabled", true);
                            $("#gr-idCard").attr("style", "color:#C0C4CC;background:#F5F7FA;border:1px solid #E4E7ED");

                        }
                    }
                });
            },

            changePersonalCenter() {
                var idCard = this.personalData.idCard;

                if (this.isChangeIdCard == true) {
                    if (! this.myCheckIdCard(idCard)) {
                        //身份证号输入不合法
                        this.$message.error("身份证号码输入错误，请重新输入");
                        return false;
                    }

                    this.$confirm('身份证号码只有一次提交机会,以后将不可修改, 是否继续?', '警告', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        axios.post("/personalCenter/modifyPersonalCenter.do", this.personalData).then((resp) => {
                            if (resp.data.flag) {
                                this.$message.success(resp.data.message);
                                window.location.href = "personalCenter.html";
                            } else {
                                this.$message.error(resp.data.message);
                            }
                        });
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });

                    return true;
                } else {
                    axios.post("/personalCenter/modifyPersonalCenter.do", this.personalData).then((resp) => {
                        if (resp.data.flag) {
                            this.$message.success(resp.data.message);
                            window.location.href = "personalCenter.html";
                        } else {
                            this.$message.error(resp.data.message);
                        }
                    });
                }
            },

            myCheckIdCard(idCard){
                var reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
                if(reg.test(idCard)){
                    return true;
                }else{
                    return false;
                }
            }
        },

        created() {
            this.findInfo();
        }

    });
</script>

</html>